//
//  CmdSetManager.swift
//  LEDSMART
//
//  Created by zj on 2022/12/31.
//  Copyright © 2022 LXF. All rights reserved.
//

import Foundation
import FastComponent

fileprivate typealias log = XXLoger

public extension CmdSetManager{
    func getCmdSet(name:String)->CmdSet?{
        for cmdset in cmdSets {
            if cmdset.name == name{
                return cmdset
            }
        }
        return nil
    }
}

public class CmdSetManager{
    public static let shared = CmdSetManager.init()
    
    public var cmdSets:[CmdSet] = []
    public static var fileList:[String] = [
    ]
    
    
    init() {
        
        for filePath in CmdSetManager.fileList {
            guard let path = Bundle.main.path(forResource: filePath, ofType: nil, inDirectory: nil)else{
                log.e("加载文件失败 > " + filePath)
                continue
            }
            
            guard let str = try? String.init(contentsOfFile: path) else{
                log.e("加载文件失败" + path)
                continue
            }
            
            guard let cmdSet = try? JSONDecoder.decode(CmdSet.self, from: str)else{
                log.e("解析失败" + str)
                continue
            }
            
            cmdSets.append(cmdSet)
        }
        log.w(cmdSets)
    }
    
    
}
